<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('修改菜单')"/>
    <th:block th:include="include :: select2-css"/>

</head>
<body class="white-bg">
<form class="form-horizontal m" id="form-job-edit" th:object="${jobs}">
    <input id="jobID" name="jobID" type="hidden" th:field="*{jobID}"/>
    <div class="form-group">
        <label class="col-sm-3 control-label ">岗位编号：</label>
        <div class="col-sm-8">
            <input class="form-control" type="text" name="jobCode" id="jobCode" th:field="*{jobCode}" required>
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-3 control-label ">岗位名称：</label>
        <div class="col-sm-8">
            <input class="form-control" type="text" name="title" id="title" th:field="*{title}" required>
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-3 control-label ">岗位简称：</label>
        <div class="col-sm-8">
            <input class="form-control" type="text" name="jobAbbr" id="jobAbbr" th:field="*{jobAbbr}" required>
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-3 control-label ">所属公司：</label>
        <div class="col-sm-8">
            <select id="compID" name="compID" class="form-control" th:onchange="getbumen(this.value)">
                <option th:each="Allcompany:${Allcompanys}" th:value="${Allcompany.compID}"
                        th:text="${Allcompany.title}" th:field="*{companyID}"></option>
            </select>
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-3 control-label ">当前所属部门：</label>
        <div class="col-sm-8">
            <select id="depID" name="depID" class="form-control" th:onchange="getgangwei(this.value)">
                <option th:each="DepartmentAll:${DepartmentAll}" th:value="${DepartmentAll.depID}"
                        th:text="${DepartmentAll.title}" th:field="*{depID}"></option>
            </select>
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-3 control-label ">上级岗位：</label>
        <div class="col-sm-8">
            <select id="adminID" name="adminID" class="form-control">
                <option th:each="JobsAll:${JobsAll}" th:value="${JobsAll.jobID}"
                        th:text="${JobsAll.title}" th:field="*{adminID}"></option>
            </select>
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-3 control-label ">岗位级别：</label>
        <div class="col-sm-8">
            <select name="jobGrade" id="jobGrade" class="form-control"
                    th:with="type=${@dict.getType('oCD_jobgrade')}">
                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"
                        th:field="*{jobGrade}"></option>
            </select>
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-3 control-label ">岗位类型：</label>
        <div class="col-sm-8">
            <select name="jobType" id="jobType" class="form-control"
                    th:with="type=${@dict.getType('oCD_JobType')}">
                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"
                        th:field="*{jobType}"></option>
            </select>
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-3 control-label ">岗位属性：</label>
        <div class="col-sm-8">
            <select name="jobProperty" id="jobProperty" class="form-control"
                    th:with="type=${@dict.getType('oCD_JobProperty')}">
                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"
                        th:field="*{jobProperty}"></option>
            </select>
        </div>
    </div>
</form>
<th:block th:include="include :: footer"/>

<script type="text/javascript">

    function edit() {
        var jobID = $("input[name='jobID']").val();
        var jobCode = $("input[name='jobCode']").val();
        var title = $("input[name='title']").val();
        var jobAbbr = $("input[name='jobAbbr']").val();
        var depID = $("#depID").val();
        var adminID = $("#adminID").val();
        var jobGrade = $("#jobGrade").val();
        var jobType = $("#jobType").val();
        var jobProperty = $("#jobProperty").val();

        $.ajax({
            cache: true,
            type: "POST",
            url: ctx + "job/edit",
            data: {
                "jobID": jobID,
                "jobCode": jobCode,
                "title": title,
                "jobAbbr": jobAbbr,
                "depID": depID,
                "adminID": adminID,
                "jobGrade": jobGrade,
                "jobType": jobType,
                "jobProperty": jobProperty
            },
            async: false,
            error: function (request) {
                $.modal.alertError("系统错误");
            },
            success: function (data) {
                $.operate.successCallback(data);
            }
        });
    }


    function getbumen(value){
        var html = "";
        $.ajax({
            async : false,
            url : "/empentry/findDep",
            data : {
                "compID" : value
            },
            type : "post",
            dataType : "json",
            success : function(data) {
                $("#depID").empty();
                $("#adminID").empty();
                var arry = data;

                for(var i=0;i<arry.length;i++){
                    html+="<option value='"
                        +arry[i].depID
                        +"'>"
                        +arry[i].title
                        +"</option>";
                }
                $("#depID").append(html);
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {

                alert("错误,请联系管理员,错误信息:"  + textStatus);
            }
        });
    }

    function getgangwei(value){
        var html = "";
        $.ajax({
            async : false,
            url : "/empentry/findJob",
            data : {
                "DepID" : value
            },
            type : "post",
            dataType : "json",
            success : function(data) {
                $("#adminID").empty();
                var arry = data;

                for(var i=0;i<arry.length;i++){
                    html+="<option value='"
                        +arry[i].jobID
                        +"'>"
                        +arry[i].title
                        +"</option>";
                }
                $("#adminID").append(html);
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                alert("错误,请联系管理员,错误信息:" );
            }
        });
    }

    function submitHandler() {
        if ($.validate.form()) {
            edit();
        }
    }

</script>
</body>
</html>
